﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace DbHelp
{
    public class ExcelHelper : DbHelper
    {
        public ExcelHelper(string dbFile)
        {
            if (dbFile == null || dbFile == string.Empty)
            {
                throw new NotImplementedException("Excel文件为空");
            }
            OleDbConnectionStringBuilder connSb = new OleDbConnectionStringBuilder();
            //if (System.IO.Path.GetExtension(dbFile) == ".xls")
            //{
            //    connSb.ConnectionString = "Provider=Microsoft.ACE.OLEDB.4.0;Data Source=" + dbFile + ";Extended ProPerties=\"Excel 8.0;HDR=YES;IMEX=0\"";
            //}
            //else
            //{
                connSb.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dbFile + ";Extended ProPerties=\"Excel 12.0;HDR=YES;IMEX=0\"";
            //}
            base.ProviderFactory = OleDbFactory.Instance;
            base.ConnectionString = connSb.ToString();
        }
    }
}
